package my_a10bbc.cn.xp.com.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.antivity.EssayActivity;
import com.example.antivity.MovieActivity;
import com.example.antivity.MusicActivity;
import com.example.antivity.WenActivity;
import com.squareup.picasso.Picasso;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.ArrayList;

import my_a10bbc.cn.xp.com.bean.IIndexThirdBean;
import sdstcom.lbq.one.R;

/**
 * Created by Administrator on 2017/1/10.
 */
public class IIndexLVAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<IIndexThirdBean> list;
    private LayoutInflater inflater;

    public IIndexLVAdapter(Context context, ArrayList<IIndexThirdBean> list) {
        this.context = context;
        this.list = list;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getViewTypeCount() {
        return 6;
    }

    @Override
    public int getItemViewType(int position) {
        return list.get(position).category;
//        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        final IIndexThirdBean obj=list.get(position);
        switch (list.get(position).category){
            case 0:
                if (convertView==null) {

                    convertView= inflater.inflate(R.layout.item_two_index, parent, false);
                    vh=new ViewHolder();
                    vh.iv1= (ImageView) convertView.findViewById(R.id.iv1_item_two_index);
                    vh.iv2= (ImageView) convertView.findViewById(R.id.iv2_item_two_index);
                    vh.iv3= (ImageView) convertView.findViewById(R.id.iv3_item_two_index);
                    vh.tv1=(TextView)convertView.findViewById(R.id.tv1_item_two_index);
                    vh.tv2=(TextView)convertView.findViewById(R.id.tv2_item_two_index);
                    vh.tv3=(TextView)convertView.findViewById(R.id.tv3_item_two_index);

                    convertView.setTag(vh);
                }else{
                    vh= (ViewHolder) convertView.getTag();
                }

                vh.tv1.setText(obj.title+"|"+obj.pic_info);
                vh.tv2.setText(obj.forward);
                vh.tv3.setText(obj.words_info);
                vh.iv3.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(context, "000", Toast.LENGTH_SHORT).show();
                    }
                });
                Picasso.with(context).load(obj.share_info.image).into(vh.iv1);
                break;
            case 1://阅读
                if (convertView==null) {

                    convertView= inflater.inflate(R.layout.item_read_index, parent, false);
                    vh=new ViewHolder();
                    vh.iv1= (ImageView) convertView.findViewById(R.id.iv1_item_read_index);
                    vh.iv2= (ImageView) convertView.findViewById(R.id.iv2_item_read_index);
                    vh.iv3= (ImageView) convertView.findViewById(R.id.iv3_item_read_index);
                    vh.tv1=(TextView)convertView.findViewById(R.id.tv1_item_read_index);
                    vh.tv2=(TextView)convertView.findViewById(R.id.tv2_item_read_index);
                    vh.tv3=(TextView)convertView.findViewById(R.id.tv3_item_read_index);
                    vh.tv4=(TextView)convertView.findViewById(R.id.tv4_item_read_index);
                    convertView.setTag(vh);
                }else{
                    vh= (ViewHolder) convertView.getTag();
                }
                convertView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent=new Intent(context, EssayActivity.class);
                        intent.putExtra("itemid",obj.item_id);
                        context.startActivity(intent);
                    }
                });
                vh.iv3.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(context, "000", Toast.LENGTH_SHORT).show();
                    }
                });
                vh.tv1.setText("-阅读-");
                vh.tv2.setText(obj.title);
                vh.tv3.setText("文 / "+obj.author.user_name);
                vh.tv4.setText(obj.forward);
                Picasso.with(context).load(obj.share_info.image).into(vh.iv1);
                break;
            case 2://连载
                if (convertView==null) {

                    convertView= inflater.inflate(R.layout.item_lianzai_index, parent, false);
                    vh=new ViewHolder();
                    vh.iv1= (ImageView) convertView.findViewById(R.id.iv1_item_lianzai_index);
                       vh.iv2= (ImageView) convertView.findViewById(R.id.iv2_item_lianzai_index);
                       vh.iv3= (ImageView) convertView.findViewById(R.id.iv3_item_lianzai_index);
                    vh.tv1=(TextView)convertView.findViewById(R.id.tv1_item_lianzai_index);
                    vh.tv2=(TextView)convertView.findViewById(R.id.tv2_item_lianzai_index);
                    vh.tv3=(TextView)convertView.findViewById(R.id.tv3_item_lianzai_index);
                    vh.tv4=(TextView)convertView.findViewById(R.id.tv4_item_lianzai_index);


                    convertView.setTag(vh);
                }else{
                    vh= (ViewHolder) convertView.getTag();
                }
                vh.tv1.setText("-连载-");
                vh.tv2.setText(obj.title);
                vh.tv3.setText("文 / "+obj.author.user_name);
                vh.tv4.setText(obj.forward);
                vh.iv3.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(context, "000", Toast.LENGTH_SHORT).show();
                    }
                });
                convertView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent=new Intent(context, WenActivity.class);
                        intent.putExtra("itemid",obj.item_id);
                        context.startActivity(intent);
                    }
                });
                Picasso.with(context).load(obj.share_info.image).into(vh.iv1);
            break;
            case 3://问答
                if (convertView==null) {

                    convertView= inflater.inflate(R.layout.item_ask_index, parent, false);
                    vh=new ViewHolder();
                    vh.iv1= (ImageView) convertView.findViewById(R.id.iv1_item_ask_index);
                   vh.iv2= (ImageView) convertView.findViewById(R.id.iv2_item_ask_index);
                   vh.iv3= (ImageView) convertView.findViewById(R.id.iv3_item_ask_index);
                    vh.tv1=(TextView)convertView.findViewById(R.id.tv1_item_ask_index);
                    vh.tv2=(TextView)convertView.findViewById(R.id.tv2_item_ask_index);
                    vh.tv3=(TextView)convertView.findViewById(R.id.tv3_item_ask_index);
                    vh.tv4=(TextView)convertView.findViewById(R.id.tv4_item_ask_index);
                    vh.tv5=(TextView)convertView.findViewById(R.id.tv5_item_ask_index);

                    convertView.setTag(vh);
                }else{
                    vh= (ViewHolder) convertView.getTag();
                }
                vh.tv1.setText("-问答-");
                vh.tv2.setText(obj.title);
                vh.tv3.setText(obj.author.user_name);
                vh.tv4.setText(obj.forward);
                vh.tv5.setText("文 / "+obj.author.user_name);
                Picasso.with(context).load(obj.share_info.image).into(vh.iv1);
                convertView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent=new Intent(context, WenActivity.class);
                        intent.putExtra("itemid",obj.item_id);
                        context.startActivity(intent);
                    }
                });
                vh.iv3.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(context, "000", Toast.LENGTH_SHORT).show();
                    }
                });
                break;
            case 4://音乐
                if (convertView==null) {

                    convertView= inflater.inflate(R.layout.item_music_index, parent, false);
                    vh=new ViewHolder();
                    vh.iv1= (ImageView) convertView.findViewById(R.id.iv1_item_music_index);
                 vh.iv2= (ImageView) convertView.findViewById(R.id.iv2_item_music_index);
                  vh.iv3= (ImageView) convertView.findViewById(R.id.iv3_item_music_index);
                    vh.tv1=(TextView)convertView.findViewById(R.id.tv1_item_music_index);
                    vh.tv2=(TextView)convertView.findViewById(R.id.tv2_item_music_index);
                    vh.tv3=(TextView)convertView.findViewById(R.id.tv3_item_music_index);
                    vh.tv4=(TextView)convertView.findViewById(R.id.tv4_item_music_index);
                    vh.tv5=(TextView)convertView.findViewById(R.id.tv5_item_music_index);
                    vh.tv6=(TextView)convertView.findViewById(R.id.tvfor_item_music_index);

                    convertView.setTag(vh);
                }else{
                    vh= (ViewHolder) convertView.getTag();
                }
                convertView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent=new Intent(context, MusicActivity.class);
                        intent.putExtra("itemid",obj.item_id);
                        context.startActivity(intent);
                    }
                });
                vh.iv3.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(context, "000", Toast.LENGTH_SHORT).show();
                    }
                });
                vh.tv1.setText("-音乐-");
                vh.tv2.setText(obj.title);
                vh.tv6.setText("--关于 《"+obj.subtitle+"》");
                vh.tv3.setText(obj.subtitle);
                vh.tv4.setText(obj.forward);
                vh.tv5.setText("文 / "+obj.author.user_name);

                ImageOptions options = new ImageOptions.Builder().setCircular(true).build();

//                Picasso.with(context).load(obj.share_info.image).into(vh.iv1);
                x.image().bind(vh.iv1,obj.share_info.image,options);
                break;

            case 5://影视
                if (convertView==null) {

                    convertView= inflater.inflate(R.layout.item_movie_index, parent, false);
                    vh=new ViewHolder();
                    vh.iv1= (ImageView) convertView.findViewById(R.id.iv1_item_movie_index);
                   vh.iv2= (ImageView) convertView.findViewById(R.id.iv2_item_movie_index);
                   vh.iv3= (ImageView) convertView.findViewById(R.id.iv3_item_movie_index);
                    vh.tv1=(TextView)convertView.findViewById(R.id.tv1_item_movie_index);
                    vh.tv2=(TextView)convertView.findViewById(R.id.tv2_item_movie_index);
                    vh.tv3=(TextView)convertView.findViewById(R.id.tv3_item_movie_index);
                    vh.tv4=(TextView)convertView.findViewById(R.id.tv4_item_movie_index);


                    convertView.setTag(vh);
                }else{
                    vh= (ViewHolder) convertView.getTag();
                }
                vh.tv1.setText("-影视-");
                vh.tv2.setText(obj.title);
                vh.tv3.setText("文 / "+obj.author.user_name);
                vh.tv4.setText(obj.forward);
                convertView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent=new Intent(context, MovieActivity.class);
                        intent.putExtra("itemid",obj.item_id);
                        context.startActivity(intent);
                    }
                });
                vh.iv3.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(context, "000", Toast.LENGTH_SHORT).show();
                    }
                });
                Picasso.with(context).load(obj.share_info.image).into(vh.iv1);
                break;
        }


        return convertView;
    }


    class ViewHolder{
        private TextView tv1,tv2,tv3,tv4,tv5,tv6;
        private ImageView iv1,iv2,iv3,iv4;
    }

}

